package com.haoshuang.zhouzhoubang.ui.page.help.detail

import android.content.Context
import android.os.Bundle
import android.webkit.WebChromeClient
import android.webkit.WebView
import com.haoshuang.zhouzhoubang.databinding.ActivityHelpDetailBinding
import com.haoshuang.zhouzhoubang.utils.WebSettingsUtils
import com.mufeng.libs.base.BaseVMActivity
import com.mufeng.libs.utils.startPage
import com.mufeng.libs.utils.toast
import com.mufeng.libs.utils.view.click
import com.mufeng.libs.utils.view.gone
import com.mufeng.libs.utils.view.visible


/**
 *  帮助详情页
 */
class HelpDetailActivity : BaseVMActivity<HelpDetailViewModel, ActivityHelpDetailBinding>() {

    companion object {
        fun launch(context: Context) {
            context.startPage<HelpDetailActivity>()
        }
    }

    private var title = ""
    private var url = ""

    override fun initIntent() {
        title = intent.getStringExtra("title") ?: ""
        url = intent.getStringExtra("url") ?: ""
    }

    override fun initView(savedInstanceState: Bundle?) {

        binding.titleBar.title = title
        binding.titleBar.leftImageView().click { finish() }

        WebSettingsUtils.setWebSettings(this, binding.webView)
        binding.webView.webChromeClient = object :WebChromeClient(){
            override fun onProgressChanged(view: WebView?, newProgress: Int) {
                super.onProgressChanged(view, newProgress)
                if (newProgress == 100) {
                    binding.progressBar.gone()
                }else{
                    binding.progressBar.visible()
                    binding.progressBar.progress = newProgress
                }
            }
        }
        binding.webView.loadUrl(url)

    }

    override fun initData() {

    }

}